/**
 * 使用位运算模拟加法
 */
function fakeAdd(a,b){
    let carry = 0;
    let curA = 0,curB = 0;
    let sum = 0;
    //let cur = 0;
    let curnum; 
    let stack = [];
    while(a > 0 || b > 0){
        curA = a%2;
        curB = b%2 ;
        curnum = curA^curB^carry;
        carry = (curA & curB) || (curB & carry) || (carry & curA);
        a>>=1;
        b>>=1;
        stack.push(curnum);
        //base <<= 1;
    }
    if(carry == 1)
        stack.push(carry);

    // if(stack.length > 0){
    //     let num = stack.pop();
    //     sum ^= num;
    // }
    while(stack.length>0){
        let num = stack.pop();
        sum ^= num;
        sum <<= 1;
    }
    return sum>>1;
}
console.log(fakeAdd(10,2));
